<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\Admin\WechatMenuStore;
use App\Http\Controllers\Controller;
use Overtrue\LaravelWeChat\Facade as EasyWechat;

class WechatMenusController extends Controller
{
    public function index()
    {
        $app = EasyWechat::officialAccount();
        $list = $app->menu->list();

        return $this->success($list['menu']['button']);
    }

    public function store(WechatMenuStore $request)
    {
        $app = EasyWechat::officialAccount();
        $buttons = $request->input('buttons');
        $result = $app->menu->create($buttons);
        if ($result['errcode']) {
            return $this->failed($result['errmsg'], $result['errcode']);
        }

        return $this->message('创建成功');
    }
}
